package com.client.data;


import com.shared.model.Proposition;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
/**
 * Extension d'une {@link ListGrid} aux {@link Proposition}
 * @author queyroi
 *
 */
public class PropositionListGrid extends ListGrid {

	
	public PropositionListGrid() {
		ListGridField messageField = new ListGridField("message", "Message");
		messageField.setWidth(250);
		ListGridField acceptedField = new ListGridField("accepted", "Decision");
		acceptedField.setWidth(100);
		
		ListGridField[] fields = new ListGridField[]{messageField,acceptedField};
		setAlternateRecordStyles(true);
		setShowAllRecords(true);		
		setFields(fields);			
		setHeight("300px");
		setAutoFitData(Autofit.HORIZONTAL);
		setAutoFitMaxWidth(670);		
		setCellHeight(40);
		setWrapCells(true);
	}
	
	public void addData(Proposition proposition){
		ListGridRecord record = new ListGridRecord();
		record.setAttribute("message", proposition.getMessage());
		if(proposition.isAccepted()){
			record.setAttribute("accepted", "Acceptee");
		}else{
			record.setAttribute("accepted", "Non Acceptee");
		}
		addData(record);
	}
}
